package com.zy.core.data.jpa.support;

import org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter;

import javax.servlet.*;
import java.io.IOException;

/**
*
* @author Dayu <yulm@sortec.com.cn>
*/
//@WebFilter(filterName="myFilter",urlPatterns="/*")
//@Configuration
public class MyOpenSessionFilter implements Filter {

    private final OpenEntityManagerInViewFilter filter;

    public MyOpenSessionFilter() {
        filter = new OpenEntityManagerInViewFilter();
        filter.setEntityManagerFactoryBeanName("entityManagerFactory");

        // .setSessionFactoryBeanName("sessionFactory_soc");

    }


    public void init(FilterConfig filterConfig) throws ServletException {
        filter.init(filterConfig);
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        filter.doFilter(request, response, chain);
    }

    public void destroy() {
        filter.destroy();
    }
}